//-----------------------------------------------------------------------
// <copyright file="Style_SiteDAOBase.cs" company="FetCo">
//     Copyright (c) FetCo. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using FetCo.Framework;
using FetCo.Framework.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ADESSA.Entities;

namespace ADESSA.Data
{    
    public abstract class Style_SiteDAOBase
    {
        #region Common methods
        public virtual Style_Site CreateStyle_SiteFromReader(IDataReader reader)
        {
            Style_Site item = new Style_Site();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("Id"))) item.Id = (int)reader["Id"];
                if (!reader.IsDBNull(reader.GetOrdinal("Ten_Css"))) item.Ten_Css = (string)reader["Ten_Css"];
                if (!reader.IsDBNull(reader.GetOrdinal("Path_Css"))) item.Path_Css = (string)reader["Path_Css"];
                if (!reader.IsDBNull(reader.GetOrdinal("UserId"))) item.UserId = (long)reader["UserId"];
                if (!reader.IsDBNull(reader.GetOrdinal("CreateDate"))) item.CreateDate = (DateTime)reader["CreateDate"];
                if (!reader.IsDBNull(reader.GetOrdinal("LastActivedDate"))) item.LastActivedDate = (DateTime)reader["LastActivedDate"];
                if (!reader.IsDBNull(reader.GetOrdinal("StatusActive"))) item.StatusActive = (byte)reader["StatusActive"];
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new DataAccessException(SR.DataAccessCreateStyle_SiteFromReaderException, ex);
            }
            return item;
        }
        #endregion
        
        #region CreateStyle_Site methods
            
        public virtual void CreateStyle_Site(Style_Site style_Site)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("spStyle_SiteInsert");
                
                database.AddInParameter(dbCommand, "@Ten_Css", DbType.String, style_Site.Ten_Css);
                database.AddInParameter(dbCommand, "@Path_Css", DbType.AnsiString, style_Site.Path_Css);
                database.AddInParameter(dbCommand, "@UserId", DbType.Int64, style_Site.UserId);
                database.AddInParameter(dbCommand, "@CreateDate", DbType.DateTime, style_Site.CreateDate);
                database.AddInParameter(dbCommand, "@LastActivedDate", DbType.DateTime, style_Site.LastActivedDate);
                database.AddInParameter(dbCommand, "@StatusActive", DbType.Byte, style_Site.StatusActive);
                database.AddOutParameter(dbCommand, "@Id", DbType.Int32, 4);
                
                DataAccessHelper.ExecuteNonQuery(database, dbCommand);
                style_Site.Id = (int)database.GetParameterValue(dbCommand, "@Id");
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new DataAccessException(SR.DataAccessCreateStyle_SiteException, ex);
            }
        }

        #endregion

        #region UpdateStyle_Site methods
        
        public virtual void UpdateStyle_Site(Style_Site style_Site)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("spStyle_SiteUpdate");            
                
                database.AddInParameter(dbCommand, "@Id", DbType.Int32, style_Site.Id);
                database.AddInParameter(dbCommand, "@Ten_Css", DbType.String, style_Site.Ten_Css);
                database.AddInParameter(dbCommand, "@Path_Css", DbType.AnsiString, style_Site.Path_Css);
                database.AddInParameter(dbCommand, "@UserId", DbType.Int64, style_Site.UserId);
                database.AddInParameter(dbCommand, "@CreateDate", DbType.DateTime, style_Site.CreateDate);
                database.AddInParameter(dbCommand, "@LastActivedDate", DbType.DateTime, style_Site.LastActivedDate);
                database.AddInParameter(dbCommand, "@StatusActive", DbType.Byte, style_Site.StatusActive);
                
                DataAccessHelper.ExecuteNonQuery(database, dbCommand);
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new DataAccessException(SR.DataAccessUpdateStyle_SiteException, ex);
            }
        }
        
        #endregion

        #region DeleteStyle_Site methods
        public virtual void DeleteStyle_Site(int id)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("spStyle_SiteDelete");
                
                database.AddInParameter(dbCommand, "@Id", DbType.Int32, id);
                
                DataAccessHelper.ExecuteNonQuery(database, dbCommand);
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new DataAccessException(SR.DataAccessDeleteStyle_SiteException, ex);
            }
        }

        #endregion

        #region GetStyle_Site methods
        
        public virtual Style_Site GetStyle_Site(int id)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("spStyle_SiteGet");
                
                database.AddInParameter(dbCommand, "@Id", DbType.Int32, id);
                
                Style_Site style_Site =  null;
                using (IDataReader reader = DataAccessHelper.ExecuteReader(database, dbCommand))
                {
                    if (reader.Read())
                    {
                        style_Site = CreateStyle_SiteFromReader(reader);
                        reader.Close();
                    }
                }
                return style_Site;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new DataAccessException(SR.DataAccessGetStyle_SiteException, ex);
            }
        }
        
        #endregion

        #region GetStyle_SiteList methods
        public virtual Style_SiteCollection GetStyle_SiteList(Style_SiteColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("spStyle_SiteGetList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                Style_SiteCollection style_SiteCollection = new Style_SiteCollection();
                using (IDataReader reader = DataAccessHelper.ExecuteReader(database, dbCommand))
                {
                    while (reader.Read())
                    {
                        Style_Site style_Site = CreateStyle_SiteFromReader(reader);
                        style_SiteCollection.Add(style_Site);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return style_SiteCollection;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new DataAccessException(SR.DataAccessGetStyle_SiteListException, ex);
            }
        }
        
        public virtual Style_SiteCollection GetStyle_SiteList(Style_SiteColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return GetStyle_SiteList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
		
		  #region GetStyle_SiteList methods
        public virtual Style_SiteCollection GetStyle_SiteListByParam(object orderBy, OrderDirection orderDirection, int page, int pageSize,string Criteria, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("spStyle_SiteGetListByParam");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
				database.AddInParameter(dbCommand, "@Criteria",  DbType.String, Criteria);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                Style_SiteCollection style_SiteCollection = new Style_SiteCollection();
                using (IDataReader reader = DataAccessHelper.ExecuteReader(database, dbCommand))
                {
                    while (reader.Read())
                    {
                        Style_Site style_Site = CreateStyle_SiteFromReader(reader);
                        style_SiteCollection.Add(style_Site);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return style_SiteCollection;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new DataAccessException(SR.DataAccessGetStyle_SiteListException, ex);
            }
        }
        
        public virtual Style_SiteCollection GetStyle_SiteListByParam(object orderBy, OrderDirection orderDirection,string Criteria)
        {            
            int totalRecords = 0;
            return GetStyle_SiteListByParam(orderBy, orderDirection, 0, 0,Criteria, out totalRecords);
        }
        
        #endregion
    }
}